package com.zlq.cn.controller.sign.ai;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.config.Config;
import com.zlq.cn.dto.param.PageParam;
import com.zlq.cn.entity.BaiduAi;
import com.zlq.cn.entity.FanyiUser;
import com.zlq.cn.service.ai.BaiduAiService;
import com.zlq.cn.service.un.FanyiUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author zhoucl
 * @date 2023年02月08日 14:58
 */
@Api(tags = "chatGPT")
@Validated
@RestController
@RequestMapping("chatgpt")
public class BaiduAiController {

    @Resource
    private BaiduAiService baiduAiService;

    @Resource
    private FanyiUserService fanyiUserService;

    @ApiOperation("ios内购回调")
    @PostMapping("/ios/callback")
    public SignApiResult<String> iosCallback(@RequestBody JSONObject param) {
        System.out.println(param);
        return SignApiResult.resultSuccess("");
    }

    @ApiOperation("用户登录/注册")
    @PostMapping("/login")
    public SignApiResult<FanyiUser> login(@RequestBody Object o) {
        FanyiUser fanyiUser = fanyiUserService.login(Config.BAIDU_AI);
        return SignApiResult.resultSuccess(fanyiUser);
    }

    @ApiOperation("AI作画-基础版列表")
    @PostMapping("/ai/baidu/txt2img/list")
    public SignApiResult<Page<BaiduAi>> txt2imgList(@ApiIgnore @RequestBody PageParam param) {
        return SignApiResult.resultSuccess(baiduAiService.txt2imgList(param.getPage()));
    }


    @ApiOperation("AI作画-基础版")
    @PostMapping("/ai/baidu/txt2img")
    public SignApiResult<BaiduAi> txt2img(@ApiIgnore @RequestBody JSONObject param) {
        return SignApiResult.resultSuccess(baiduAiService.txt2img(param));
    }

    @ApiOperation("百度ai")
    @ApiImplicitParam(name = "aiType",
            value = "ai类型；txt2img，getImg，create_vidpress，hot_list，hot_list_advanced_domain，hot_list_advanced_location，vein_list，" +
                    "search_news，location_extract；除了这个参数其他的参数以及返回结果直接查看ai文档：https://ai.baidu.com/ai-doc/NLP/Ml9i5amtk",
            paramType = "body", required = true)
    @PostMapping("/ai/baidu")
    public SignApiResult<JSONObject> aiBaidu(@ApiIgnore @RequestBody JSONObject param) throws IOException {
//        User user = SignApiBootstrap.requestUser();
        return SignApiResult.resultError("请升级新版");
//        String aiType = param.getString("aiType");
//        String url = "";
//        if ("txt2img".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/ernievilg/v1/txt2img";
//        }
//        if ("getImg".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/ernievilg/v1/getImg";
//        } else if ("create_vidpress".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/brain/vidpress/v1/create_vidpress";
//        } else if ("hot_list".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/creation/v1/hot_list/domain";
//        } else if ("hot_list_advanced_domain".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/creation/v1/hot_list_advanced/domain";
//        } else if ("hot_list_advanced_location".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/creation/v1/hot_list_advanced/location";
//        } else if ("vein_list".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/creation/v1/event/vein_list";
//        } else if ("search_news".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/creation/v1/search_news";
//        } else if ("location_extract".equals(aiType)) {
//            url = "https://aip.baidubce.com/rpc/2.0/creation/v1/location_extract";
//        }
//        return SignApiResult.resultSuccess(baiduAiService.request(param, url));
    }
}
